package cn.java68.printer;

import org.springframework.stereotype.Service;

@Service
public class TextPaper implements Paper {

    private  int lines;//一页多少行
    private int words;//一行几个字
    @Override
    public void print(String str) {
        //模拟打印的过程
        char []cr=str.toCharArray();
        int l=0,w=0;
        int pageNo=1;//页数
        for(char c:cr){
            System.out.print(c);
            w++;
            if(w==words)
            {
                w=0;
                l++;
                System.out.println();
                if(l==lines){
                    l=0;
                    System.out.println("----"+(pageNo++)+"----");
                }
            }
        }
        if(w!=0||l!=0)
            System.out.println("\n----"+pageNo+"----");
    }

    public void setLines(int lines) {
        this.lines = lines;
    }

    public void setWords(int words) {
        this.words = words;
    }
}
